package com.langll.mcp.portfolio.mcp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.langll.mcp.portfolio.mapper.PortfolioProductMapper;
import com.langll.mcp.portfolio.model.BusinessSegmentRequest;
import com.langll.mcp.portfolio.model.BusinessSegmentResponse;
import com.langll.mcp.portfolio.model.PortfolioProduct;
import com.langll.mcp.portfolio.service.IPortfolioProductService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PortfolioProductMCP {

    private static final Logger LOGGER = LoggerFactory.getLogger(PortfolioProductMCP.class);

    private final IPortfolioProductService iPortfolioProductService;

    @Tool(name = "getPortfolioByBusinessData", description = "查询portfolio的数量", returnDirect=true)
    public List<BusinessSegmentResponse> BusinessSegmentResponse(BusinessSegmentRequest request) {
        LOGGER.info("BusinessSegmentResponse请求参数: {}", request.getBusinessSegment());
        return iPortfolioProductService.getBusinessSegmentGroup(request.getBusinessSegment()).stream()
                .map(map -> {
                    BusinessSegmentResponse response = new BusinessSegmentResponse();
                    response.setPlanningCycle((String) map.get("PLANNING_CYCLE"));
                    response.setBusinessSegment((String) map.get("BUSINESS_SEGMENT"));
                    response.setCount(((Long) map.get("count")).intValue());
                    return response;
                })
                .toList();
    }
}
